package jwdt.xadmin.goods.action;

import jwdt.common.action.BaseAction;
import jwdt.xadmin.goods.bean.TGoods;
import jwdt.xadmin.goods.bean.TGoodsUse;
import jwdt.xadmin.goods.service.GoodsManageService;
import jwdt.xadmin.goods.service.GoodsUseManageService;
import jwdt.xadmin.system.bean.TUser;

import com.ezerg.db.ext.PageUtil;
import com.ezerg.util.DateUtil;
import com.ezerg.web.Form;
import com.ezerg.web.Module;
import com.ezerg.web.Page;
import com.ezerg.web.annotation.Controller;
import com.ezerg.web.annotation.RequestMapping;

@Controller("/xadmin/goods")
public class GoodsUseManageAction extends BaseAction {

	GoodsUseManageService goodsUseManageService = app.getBean("GoodsUseManageService");
	
	GoodsManageService goodsManageService = app.getBean("GoodsManageService");
	
	@RequestMapping("/selectGoodsUseList")
	public Page doSelectGoodsList(Form f,Module m)throws Exception{
		PageUtil pu = (PageUtil) f.copy2Class(PageUtil.class);
		return m.getWritePage(f, goodsUseManageService.selectGoodsUseList(pu).toJson());
	}
	
	@RequestMapping("/selectOneGoodsUse")
	public Page doSelectOneGoods(Form f,Module m)throws Exception{
		int useid = f.getInt("useid");
		return m.getJsonPage(f, goodsUseManageService.selectOneGoodsUse(useid));
	}
	
	@RequestMapping("/saveGoodsUse")
	public Page doSaveGoodsUse(Form f,Module m)throws Exception{
		TUser userInfo = (TUser)f.getSession("userInfo");
		int useid = f.getInt("useid");
		TGoodsUse obj = (TGoodsUse) f.copy2Class(TGoodsUse.class);
		obj.setUserid(userInfo.getUserid());
		obj.setDt(DateUtil.getDateTime());
		obj.setZt(0);
		TGoods tgoods = goodsManageService.selectOneGoods(obj.getGoodsid());
		return m.getJsonPage(f, goodsUseManageService.saveGoodsUse(useid, obj,tgoods));
	}
	
	@RequestMapping("/delGoodsUse")
	public Page doDelGoodsUse(Form f,Module m)throws Exception{
		int useid = f.getInt("useid");
		return m.getJsonPage(f, goodsUseManageService.delGoodsUse(useid));
	}
	
	@RequestMapping("/goodsUseChkact")
	public Page doGoodsUseChkact(Form f,Module m)throws Exception{
		int useid = f.getInt("useid");
		int zt = f.getInt("zt");
		return m.getJsonPage(f, goodsUseManageService.goodsUseChkact(useid,zt));
	}
	
}
